/*
 * @(#) LotInfo.java 2013-8-7 下午6:11:59
 *
 * Copyright 2013 Rockwell Automation, Inc. All rights reserved.
 * Rockwell Automation PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */package com.osi.mes.pm.object;

import java.math.BigDecimal;
import java.util.Vector;

import com.datasweep.compatibility.client.BillOfMaterials;
import com.datasweep.compatibility.client.BomItem;
import com.datasweep.compatibility.client.Lot;
import com.datasweep.plantops.common.constants.ITrackedObjectConstants;

 /**
  * 批次信息
  * @author Nemo, 2013-8-7 下午6:12:02
  */
public class LotInfo
{
	Lot lot;
	String lotName;
	BigDecimal quantity;
	BillOfMaterials billOfMaterials;
	public LotInfo(Lot lot)
	{
		this.lot = lot;
		this.lotName = lot.getName();
		this.quantity = lot.getPreciseQuantity();
		this.billOfMaterials = lot.getBillOfMaterials();
	}
	
	public LotInfo(String lotName,Object quantity,BillOfMaterials billOfMaterials) throws Exception
	{
		this.lotName = lotName;
		this.quantity = new BigDecimal(quantity.toString());
		this.billOfMaterials = billOfMaterials;
		billOfMaterials.refresh();
		Vector bomItems = this.billOfMaterials.getBomItems();
		for (int i = 0; i < bomItems.size(); i++)
		{
			BomItem bomItem = (BomItem) bomItems.get(i);
			BigDecimal originalQuantity = bomItem.getPreciseQuantity();
			bomItem.setPreciseQuantity(this.quantity.multiply(originalQuantity));
		}
	}
	
	/**
	 * 是否是新建的
	 */
	public boolean isCreated()
	{
		if(lot == null)
		{
			return true;
		}
		else
		{
			return ITrackedObjectConstants.STATUS_STR_CREATED.equals(lot.getCurrentStatus());
		}
	}
	
	public Lot getLot()
	{
		return this.lot;
	}
	
	public BillOfMaterials getBom()
	{
		return this.billOfMaterials;
	}
	
	public String getLotName()
	{
		return this.lotName;
	}
	
	public float getQuantity()
	{
		return this.quantity.floatValue();
	}
	
	public BigDecimal getQuantityValue()
	{
		return this.quantity;
	}
	
	public void setQuantity(float value)
	{
		this.quantity = new BigDecimal(value);
	}
	
}
